package com.ruoyi.web.controller.business;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Platforms;
import com.ruoyi.system.service.IPlatformsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 平台Controller
 * 
 * @author zzbird
 * @date 2023-11-14
 */
@Api("平台管理")
@RestController
@RequestMapping("/business/platforms")
public class PlatformsController extends BaseController
{
    @Autowired
    private IPlatformsService platformsService;

    /**
     * 查询平台列表
     */
    @ApiOperation("查询平台列表")
//    @PreAuthorize("@ss.hasPermi('business:platforms:list')")
    @GetMapping("/list")
    public TableDataInfo list(Platforms platforms)
    {
        startPage();
        List<Platforms> list = platformsService.selectPlatformsList(platforms);
        return getDataTable(list);
    }

    /**
     * 导出平台列表
     */
    @ApiOperation("导出平台列表")
    @PreAuthorize("@ss.hasPermi('business:platforms:export')")
    @Log(title = "平台", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Platforms platforms)
    {
        List<Platforms> list = platformsService.selectPlatformsList(platforms);
        ExcelUtil<Platforms> util = new ExcelUtil<Platforms>(Platforms.class);
        util.exportExcel(response, list, "平台数据");
    }

    /**
     * 获取平台详细信息
     */
    @ApiOperation("获取平台详细信息")
    @PreAuthorize("@ss.hasPermi('business:platforms:query')")
    @GetMapping(value = "/{platformId}")
    public AjaxResult getInfo(@PathVariable("platformId") Long platformId)
    {
        return success(platformsService.selectPlatformsByPlatformId(platformId));
    }

    /**
     * 新增平台
     */
    @ApiOperation("新增平台")
    @PreAuthorize("@ss.hasPermi('business:platforms:add')")
    @Log(title = "平台", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Platforms platforms)
    {
        return success(platformsService.insertPlatforms(platforms));
    }

    /**
     * 修改平台
     */
    @ApiOperation("修改平台")
    @PreAuthorize("@ss.hasPermi('business:platforms:edit')")
    @Log(title = "平台", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Platforms platforms)
    {
        return toAjax(platformsService.updatePlatforms(platforms));
    }

    /**
     * 删除平台
     */
    @ApiOperation("删除平台")
    @PreAuthorize("@ss.hasPermi('business:platforms:remove')")
    @Log(title = "平台", businessType = BusinessType.DELETE)
	@DeleteMapping("/{platformIds}")
    public AjaxResult remove(@PathVariable Long[] platformIds)
    {
        return toAjax(platformsService.deletePlatformsByPlatformIds(platformIds));
    }
}
